package concursos.ejb;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import concursos.daos.DisciplinaDAO;
import concursos.interfaces.DisciplinaService;
import concursos.modelos.Disciplina;

@Stateless
@LocalBean
public class DisciplinaEjb implements DisciplinaService {

	private DisciplinaDAO dao;
	@PersistenceContext(unitName = "meusconcursosejb")
	private EntityManager manager;

	public DisciplinaDAO getDao() {
		if (this.dao == null)
			this.dao = new DisciplinaDAO(this.manager);
		return this.dao;
	}

	public DisciplinaEjb() {
	}

	@Override
	public void cadastrarDisciplina(Disciplina disciplina) {
		this.getDao().adicionarDisciplina(disciplina);

	}

	@Override
	public void atualizarDisciplina(Disciplina disciplina) {
		this.getDao().atualizarDisciplina(disciplina);

	}

	@Override
	public void excluirDisciplina(Disciplina disciplina) {
		this.getDao().excluirDisciplina(disciplina);
	}

	@Override
	public List<Disciplina> listarDisciplina(int usuario) {
		return this.getDao().listarDisciplina(usuario);
	}

	@Override
	public Disciplina buscaPorId(int id) {
		return this.getDao().buscaPorId(id);
	}

	@Override
	public List<Disciplina> buscarPorConcurso(int id) {
		List<Disciplina> disciplinas = new ArrayList<Disciplina>();
		disciplinas = this.getDao().buscarPorConcurso(id);
		return disciplinas;
	}

}
